package org.easy.core.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 读取 ClassPathResource文本
 */
@Slf4j
public class ResourceReaderUtil {

    public static String readFileContent(String fileName) {
        StringBuilder content = new StringBuilder();
        ClassPathResource resource = new ClassPathResource(fileName);
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                content.append(line).append("\n");
            }
        } catch (IOException e) {
            log.error("read fail {} reason {}", fileName, e.getMessage());
        }
        return content.toString();
    }
}
